package com.liuya.db.script;

import com.liuya.safe.util.Constants;
import com.liuya.safe.model.SafeQuery;

import java.io.Serializable;

public class QueryRef extends DefineVariable implements Serializable {

	private String id;
	private SafeQuery query;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String toScript() {
		return toScript(false);
	}

	/**
	 * Script likes: Object v = queryManager.getQuery( queryId
	 * ).executeQueryRef(user, context, returnCollection );
	 */
	public String toScript(boolean returnCollection) {
		String v = getVariableName();
		String user = Constants.USER_KEY;
		String context = Constants.CONTEXT;
		String queryManager = Constants.QUERY_MANAGER;
		StringBuffer buff = new StringBuffer();
		buff.append(" Object ").append(v).append(" = ").append(queryManager).append(".getQuery(").append(id).append(").executeQueryRef(").append(user).append(", ").append(context).append(", ").append(returnCollection).append(" ); ").append("\n");
		return buff.toString();
	}

	public SafeQuery getQuery() {
		return query;
	}

	public void setQuery(SafeQuery query) {
		this.query = query;
	}
}
